package ngamejava2;

import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;

public class ParallaxPlaneManager extends PlaneManager
{
	public ParallaxPlaneManager()
	{
		this(1,1);
	}

	public ParallaxPlaneManager(int width, int height)
	{
		super(width, height);
	}

	public AffineTransform getParallaxTransform(ParallaxGamePlane plane)
	{
		float sx = getViewport().width / getCamera().width;
		float sy = getViewport().height / getCamera().height;

		AffineTransform xform = new AffineTransform();
		xform.translate(getViewport().x - getCamera().x * sx / plane.getDistance(),
						getViewport().y - getCamera().y * sy / plane.getDistance());
		xform.scale(sx, sy);

		return xform;
	}

	@Override
	public void render(Graphics2D g, long currentFrame)
	{
		Graphics2D gg = (Graphics2D) g.create();
		resetIterator();
		while (iteratorHasNext())
		{
			gg.setTransform(getParallaxTransform((ParallaxGamePlane)getCurrentObject()));
			getCurrentObject().render(gg, currentFrame);
		}
	}
}